package com.mba.activity;

import java.util.ArrayList;
import java.util.List;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.mba.adapter.HomeListAdapter;
import com.mba.base.BaseActivity;
import com.mba.bean.Message;
import com.mba.service.MessageService;
import com.mba.util.AsyncImageLoader;
import com.mba.util.Tools;
import com.mba.util.AsyncImageLoader.ImageCallback;

public class UserMainPageActivity extends BaseActivity {
	private ListView userPageListView;
	private  ArrayList<Message> contentList;
	private Button backButton;
	private MessageService msgService;
	private ImageView avater;
	private TextView userName;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		NOTITLE();
		setContentView(R.layout.user_main_page_activity);
		backButton = (Button) findViewById(R.id.user_page_back_button);
		backButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				finish();
			}
		});
		
	
		try {
			userPageListView = (ListView) findViewById(R.id.user_page_lv);
			avater = (ImageView) findViewById(R.id.user_page_avater);
			userName = (TextView) findViewById(R.id.user_page_avater_name);
			this.contentList = (ArrayList<Message>) this.msgService.getHomeTimeline(Tools.GET_LOCAL);
			if (this.contentList!=null) {
				//设置该页显示的主要内容
				userPageListView.setAdapter(new HomeListAdapter(this, contentList));
				
				AsyncImageLoader asyncImageLoader = new AsyncImageLoader();
				//异步加载图片
				 Drawable avater_image = asyncImageLoader.loadDrawable(
						 this.contentList.get(1).getUser().getHeadPic(), avater,
		                 new ImageCallback() {
		                     public void imageLoaded(Drawable drawable,
		                             ImageView iv, String url) {
		                         iv.setImageDrawable(drawable);
		                     }
		        });
				if (avater_image != null) {
					//设置main user page的头像
					avater.setImageDrawable(avater_image);	
				}
				//设置main user page 的用户名
				userName.setText(this.contentList.get(1).getUser().getUserName());
				
			}
			else {
				finish();
				System.out.println("取不到数据啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊  " +
						"" +
						"啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊" +
						"啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊" +
						"啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊" +
						"啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊" +
						"啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊" +
						"啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊");
			}
	
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
	}
    
	
}
